﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http.ExceptionHandling;
using System.Web.Mvc;

namespace AspNetDemo.Services
{
    public class MyExceptionHandler : ExceptionHandler
    {
        public override bool ShouldHandle(ExceptionHandlerContext context)
        {
            return true;
        }

        public override void Handle(ExceptionHandlerContext context)
        {
            context.Result = new System.Web.Http.Results.ExceptionResult(context.Exception,
                true,
                new System.Net.Http.Formatting.DefaultContentNegotiator(),
                context.Request,
                new[] { new System.Net.Http.Formatting.JsonMediaTypeFormatter() });            
        }
    }
}